package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.AidMapper;
import com.java2207.group1.pojo.Aid;
import com.java2207.group1.service.AidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Service("aidService")
public class AidServiceImpl  implements AidService {

    @Autowired
    private AidMapper aidMapper;


    @Override
    public LayuiPageVo<Aid> aidPageAll(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);
        List<Aid> layuiPageVo = aidMapper.aidPageAll(params);

        PageInfo<Aid> pageInfo = new PageInfo<>(layuiPageVo);
        LayuiPageVo<Aid> aidLayuiPageVo = new LayuiPageVo<>();
        aidLayuiPageVo.setCode(0);
        aidLayuiPageVo.setMsg("分页列表数据");
        aidLayuiPageVo.setCount(pageInfo.getTotal());//总记录数
        aidLayuiPageVo.setData(pageInfo.getList());//分页的列表数据


        return aidLayuiPageVo;
    }

    @Override
    public int delectAid(int id) {
       int aid = aidMapper.delectAid( id);
        return aid;
    }

    @Override
    public int addAid(Aid aid) {
        int add =aidMapper.addAid(aid);
        return add;
    }

    @Override
    public int updateAid(Aid aid) {
        int updateAid=aidMapper.updateAid(aid);
        return updateAid;
    }

    @Override
    public int delectAidId(String ids) {
        String[] arrid=ids.split(",");
        int i= aidMapper.deleteAidIds(arrid);
        return i;
    }
}
